//
//  EditSortViewController.m
//  SAT_NET
//
//  Created by lanou3g on 16/3/4.
//  Copyright © 2016年 郭丹. All rights reserved.
//

#import "EditSortViewController.h"
#import "SortCell.h"

@interface EditSortViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property(nonatomic, strong) UICollectionView *collectionV;
@property(nonatomic, strong) NSMutableArray *arrayAllData;


@end

@implementation EditSortViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setData];
    [self setViews];
    [self setDelegate];
    
    [self.collectionV registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"id"];
    [self.collectionV registerClass:[SortCell class] forCellWithReuseIdentifier:@"collection_id"];
    
}

- (void)setData {
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sort" ofType:@"plist"];
    self.arrayAllData = [NSMutableArray arrayWithContentsOfFile:filePath];
    
    for (NSString *str in self.arrayAllData) {
        if ([self.arrayAddData containsObject:str] == NO) {
            [self.arrayRemoveData addObject:str];
        }
    }
}

- (void)setViews {
    //添加NavigationController
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self];
//    nav.view.frame = CGRectMake(0, 20, kScreenW, 44);
    self.title = @"更多";
    nav.navigationBar.frame = CGRectMake(0, 20, kScreenW, 44);
    nav.navigationBar.backgroundColor = [UIColor redColor];
    nav.navigationBar.translucent = YES;
    [self.view addSubview:nav.view];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"cancel"] style:(UIBarButtonItemStyleDone) target:self action:@selector(rightAction)];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(60, 30);
    flowLayout.minimumLineSpacing = 10;
    flowLayout.minimumInteritemSpacing = 20;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    
    self.collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, kScreenW, kScreenH - 64 - 150) collectionViewLayout:flowLayout];
    self.collectionV.backgroundColor = [UIColor colorWithRed:244 / 255.0
                                                       green:244 / 255.0
                                                        blue:244 / 255.0
                                                       alpha:1];
    

    
}

- (void)rightAction {
    
}

- (void)setDelegate {
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    [self.view addSubview:self.collectionV];
}

- (NSInteger )collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return self.arrayAddData.count;
    } else {
        return self.arrayRemoveData.count;
    }
}

- (NSInteger )numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    SortCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection_id" forIndexPath:indexPath];
    if (indexPath.section == 0) {
        cell.lable.text = self.arrayAddData[indexPath.row];
    } else {
        cell.lable.text = self.arrayRemoveData[indexPath.row];
    }
 
    cell.backgroundColor = [UIColor whiteColor];
    cell.layer.cornerRadius = 15;
    cell.layer.masksToBounds = YES;
    return cell;
    
}


//- (NSMutableArray *)arrayAllData {
//    if (!_arrayAllData) {
//        _arrayAddData = [NSMutableArray array];
//    }
//    return _arrayAllData;
//}

- (NSMutableArray *)arrayRemoveData {
    if (!_arrayRemoveData) {
        _arrayRemoveData = [NSMutableArray array];
    }
    return _arrayRemoveData;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
